/**
 * UploadDocServiceImpl.java
 */
package com.prs.crm.service.doc.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.courser.hibernate.QueryExample;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.doc.UploadDocDao;
import com.prs.crm.domain.doc.UploadDoc;
import com.prs.crm.domain.document.knowledge.Doc;
import com.prs.crm.service.doc.UploadDocService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */
/**
 * @author Administrator
 *
 */
public class UploadDocServiceImpl extends BaseServiceImpl<UploadDoc, UploadDocDao> implements
		UploadDocService {

	@Override
	public List<UploadDoc> getAllUploadDocs() {
		// TODO Auto-generated method stub
		return this.getDao().getAllUploadDocs();
	}
	@Override
	public Collection<UploadDoc> convertToUploadDoc(String ids) {
		// TODO Auto-generated method stub
		try{
			Collection<UploadDoc> uploadDocs = new ArrayList<UploadDoc>();
			for(String id : ids.split(",")) {
				UploadDoc uploadDoc = new UploadDoc();
				uploadDoc.setId(Integer.valueOf(id));
				uploadDocs.add(uploadDoc);
			}
			return uploadDocs;
			}catch (NumberFormatException e) {
				e.printStackTrace();
				return null;
				}
	}

	@Override
	public Collection<UploadDoc> getRootUploadDoc() {
		// TODO Auto-generated method stub
		return this.getDao().getRootUploadDoc();
	}

	@Override
	public UploadDoc getUploadDocById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getUploadDocById(id);
	}

	@Override
	public void saveUploadDocs(UploadDoc uploadDoc, File file, String fileName) {
      Attach cAttach=FileUtil.getInstance().saveFile(file, fileName,"",Constrains.UPLOAD_DIR_UPLOADDOC);
		
		if(cAttach.getSrc()!=null){
			uploadDoc.setDocument_file(cAttach.getSrc());
		}
		this.getDao().save(uploadDoc);
		
	}
	/* (non-Javadoc)
	 * @see com.prs.crm.service.doc.UploadDocService#removeUploadDoc(java.lang.Integer)
	 */
	@Override
	public int removeUploadDoc(Integer id) {
		// TODO Auto-generated method stub
		return this.getDao().removeUploadDoc(id);
	}
	
	
}
